package com.wei.order.controller;

import com.wei.common.entity.Order;
import com.wei.common.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Random;

/**
 * @author weichuanyuan
 * @version 1.0
 * @date 2021/8/29 9:33
 */

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 下订单
     * @return
     */
    @GetMapping("/placeOrder")
    public String placeOrder(){
        int random = new Random().nextInt(1000);

        Order order = new Order();
        order.setCreateDate(new Date());
        order.setOrderAmount(new BigDecimal(random));
        order.setOrderName("订单" + random);

        orderService.checkOrder(order);
        orderService.placeOrder(order);
        return "sucess";
    }

}
